package com.googlecode.delivery.model;

import java.io.File;
import java.io.IOException;

/**
 * The Deployment Unit with all mendatory propeties : link to artefact,
 * in-memory configurable (templates) files and currrent environement.
 * 
 * @author kst
 * 
 */
public class DeploymentUnit {
	/** Packaged Environement file name. */
	public static String ENVIRONMENT_FILE_NAME = "env.properties";
	public static String DELIVERY_ROOT_DIR = "META-INF/delivery/";

	private String name;
	private String type;
	private File explodedDir;
	private Environment environment;

	public String getType() {
		return type;
	}

	/**
	 * @param name
	 * @param type
	 */
	public DeploymentUnit(String name, String type) {
		this.name = name;
		this.type = type;
	}

	public File getExplodedDir() {
		return explodedDir;
	}

	public void setExplodedDir(File explodedDir) {
		this.explodedDir = explodedDir;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Environment getEnvironment() {
		return environment;
	}

	public void setEnvironment(Environment environment) {
		this.environment = environment;
	}

	public String getArtefactName() {
		return name + "." + type;
	}

	public File getConfigDir() {
		return new File(getExplodedDir().getAbsolutePath() + "/"
				+ DeploymentUnit.DELIVERY_ROOT_DIR + "/" + getType());
	}

	public File getEnvFile() throws IOException {
		return new File(getExplodedDir().getAbsolutePath() + "/"
				+ DeploymentUnit.DELIVERY_ROOT_DIR + "/"
				+ DeploymentUnit.ENVIRONMENT_FILE_NAME);
	}

}
